package com.itheima.cotroller;

import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.pojo.CheckItem;
import com.itheima.vo.checkitemVo;
import com.itheima.sercive.CheckItemService;
import com.itheima.vo.PageRequestDTO;
import com.itheima.vo.PageResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.itheima.common.entity.Result;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/checkitem")
public class CheckItemController {
    @Autowired
    private CheckItemService checkItemService;
    // 新增检查项
    @PostMapping("/add")
    public Result add(@RequestBody CheckItem checkItem) {
        checkItemService.add(checkItem);
        return Result.success();
    }

    // 根据id删除检查项
    @DeleteMapping("/delete")
    public Result delete(@RequestParam Integer id) {
        checkItemService.deleteById(id);
        return Result.success();
    }

    // 查询所有检查项
    @GetMapping("/findAll")
    public Result<List<CheckItem>> findAll() {
        List<CheckItem> list = checkItemService.findAll();
        return Result.success(list);
    }

    // 根据id查询检查项
    @GetMapping("/findById")
    public Result<CheckItem> findById(@RequestParam Integer id) {
        CheckItem checkItem = checkItemService.findById(id);
        return Result.success(checkItem);
    }

    // 编辑检查项
    @PutMapping("/edit")
    public Result edit(@RequestBody CheckItem checkItem) {
        checkItemService.update(checkItem);
        return Result.success();
    }


    // 分页查询
    @PostMapping("/findPage")
    public Result<PageResult> findPage(@RequestBody QueryPageBean queryPageBean) {
        PageResult pageResult = checkItemService.findPage(queryPageBean);
        return Result.success(pageResult);
    }

    // 根据检查组id查询关联的检查项id
    @GetMapping("/findCheckItemIdsByCheckGroupId")
    public Result<List<Integer>> findCheckItemIdsByCheckGroupId(@RequestParam Integer id) {
        List<Integer> ids = checkItemService.findCheckItemIdsByCheckGroupId(id);
        return Result.success(ids);
    }
}
